<?php

class AtomFeedBean extends Databean {

    public function addEntry($entry) {
        if (!is_a($entry,'AtomEntryBean'))
            return false;

        if ($entry->updated->isAfter($this->updated)) {
            $this->updated=$entry->updated;
        }
        $key=$entry->published->torfc3339().$entry->id; // echo "<p>$key</p>";
        $this->entries[$key]=$entry;
        krsort($this->entries);
        // echo '<pre>'; print_r($entries);
        return true;
    }

    /**
     * @var string
     */
    public $id;
    protected function _id_required() {
        return true;
    }

    /**
     * @var string
     */
    public $title;
    protected function _title_required() {
        return true;
    }

    public $subtitle;

    /**
     * @var DateTimeBean
     */
    public $updated;
    protected function _updated_required() {
        return true;
    }
    protected function _updated_inputFilter($x) {
        return $this->_toDateTimeBean($x);
    }
    protected function _updated_autoValue() {
        return new DateTimeBean('1900-01-01');
    }

    /**
     * @var array AtomEntry elements ordered by updated desc
     */
    public $entries=array();

	/**
	* value to datetimebean
	* @param mixed $value
	* @access private
	* @return datetimebean
	*/
	function & _toDateTimeBean($value) {
		if (class_exists('datetimebean') and !is_null($value) and $value)
			$value=&new datetimebean($value);
		return $value;
	}/**/
}
